﻿using AutoMapper;
using mozhi.smarterp.BasicData.Currencies;
using mozhi.smarterp.BasicData.Customers;
using mozhi.smarterp.BasicData.Employees;
using mozhi.smarterp.BasicData.ExpenseItems;
using mozhi.smarterp.BasicData.NumberRules;
using mozhi.smarterp.BasicData.Organizations;
using mozhi.smarterp.BasicData.Products;
using mozhi.smarterp.BasicData.Suppliers;
using mozhi.smarterp.BasicData.TaxRates;
using mozhi.smarterp.BasicData.Units;
using mozhi.smarterp.BasicData.Warehouses;

namespace mozhi.smarterp.BasicData;

public class BasicDataApplicationAutoMapperProfile : Profile
{
    public BasicDataApplicationAutoMapperProfile()
    {
        /* You can configure your AutoMapper mapping configuration here.
         * Alternatively, you can split your mapping configurations
         * into multiple profile classes for a better organization. */

        CreateMap<Organization, OrganizationDto>()
            .ForMember(des => des.Id, opt => opt.MapFrom(src => src.Id))
            .ForMember(des => des.OfficialName, opt => opt.MapFrom(src => src.OfficialName))
            .ForMember(des => des.Name, opt => opt.MapFrom(src => src.Name))
            .ForMember(des => des.TaxIDNumber, opt => opt.MapFrom(src => src.TaxIDNumber))
            .ForMember(des => des.ActivatedDate, opt => opt.MapFrom(src => src.ActivatedDate))
            .ForMember(des => des.AccountingStandard, opt => opt.MapFrom(src => src.AccountingStandard))
            .ForMember(des => des.StandardCurrencyId, opt => opt.MapFrom(src => src.StandardCurrencyId));

        CreateMap<Currency, CurrencyDto>()
            .ForMember(des => des.Id, opt => opt.MapFrom(src => src.Id))
            .ForMember(des => des.Code, opt => opt.MapFrom(src => src.Code))
            .ForMember(des => des.Name, opt => opt.MapFrom(src => src.Name))
            .ForMember(des => des.Symbol, opt => opt.MapFrom(src => src.Symbol));

        CreateMap<Unit, UnitDto>()
            .ForMember(des => des.Id, opt => opt.MapFrom(src => src.Id))
            .ForMember(des => des.Code, opt => opt.MapFrom(src => src.Code))
            .ForMember(des => des.Name, opt => opt.MapFrom(src => src.Name));

        CreateMap<Product, ProductDto>()
            .ForMember(des => des.Id, opt => opt.MapFrom(src => src.Id))
            .ForMember(des => des.Code, opt => opt.MapFrom(src => src.Code))
            .ForMember(des => des.Name, opt => opt.MapFrom(src => src.Name))
            .ForMember(des => des.Type, opt => opt.MapFrom(src => src.Type))
            .ForMember(des => des.ImageId, opt => opt.MapFrom(src => src.ImageId))
            .ForMember(des => des.Activated, opt => opt.MapFrom(src => src.Activated))
            .ForMember(des => des.BarCode, opt => opt.MapFrom(src => src.BarCode))
            .ForMember(des => des.Model, opt => opt.MapFrom(src => src.Model))
            .ForMember(des => des.Saleable, opt => opt.MapFrom(src => src.Saleable))
            .ForMember(des => des.Purchasable, opt => opt.MapFrom(src => src.Purchasable))
            .ForMember(des => des.Producible, opt => opt.MapFrom(src => src.Producible))
            .ForMember(des => des.Outsourceable, opt => opt.MapFrom(src => src.Outsourceable))
            .ForMember(des => des.Assetable, opt => opt.MapFrom(src => src.Assetable))
            .ForMember(des => des.BasicUnitId, opt => opt.MapFrom(src => src.BasicUnitId))
            .ForMember(des => des.DefaultTaxRateId, opt => opt.MapFrom(src => src.DefaultTaxRateId))
            .ForMember(des => des.BasicUnitName, opt => opt.Ignore())
            .ForMember(des => des.DefaultTaxRateName, opt => opt.Ignore());



        CreateMap<Product, ProductListDto>()
            .ForMember(des => des.Id, opt => opt.MapFrom(src => src.Id))
            .ForMember(des => des.Code, opt => opt.MapFrom(src => src.Code))
            .ForMember(des => des.Name, opt => opt.MapFrom(src => src.Name))
            .ForMember(des => des.Type, opt => opt.MapFrom(src => src.Type))
            .ForMember(des => des.ImageId, opt => opt.MapFrom(src => src.ImageId))
            .ForMember(des => des.Activated, opt => opt.MapFrom(src => src.Activated))
            .ForMember(des => des.BasicUnitId, opt => opt.MapFrom(src => src.BasicUnitId))
            .ForMember(des => des.BasicUnitName, opt => opt.Ignore())
            .ForMember(des => des.DefaultTaxRateName, opt => opt.MapFrom(src => src.DefaultTaxRateId))
            .ForMember(des => des.DefaultTaxRateValue, opt => opt.Ignore());

        CreateMap<TaxRate, TaxRateDto>()
            .ForMember(des => des.Id, opt => opt.MapFrom(src => src.Id))
            .ForMember(des => des.Code, opt => opt.MapFrom(src => src.Code))
            .ForMember(des => des.Name, opt => opt.MapFrom(src => src.Name))
            .ForMember(des => des.Rate, opt => opt.MapFrom(src => src.Rate));

        CreateMap<Customer, CustomerListDto>();

        CreateMap<Customer, CustomerDto>();

        CreateMap<CustomerContactItem, CustomerContactItemDto>();

        CreateMap<Supplier, SupplierListDto>();

        CreateMap<Supplier, SupplierDto>();

        CreateMap<SupplierContactItem, SupplierContactItemDto>();

        CreateMap<Employee , EmployeeDto>()
            .ForMember(des => des.DepartmentName, opt => opt.Ignore());

        CreateMap<ProductAuxiliaryUnit, ProductAuxiliaryUnitDto>()
            .ForMember(des => des.ProductCode, opt => opt.Ignore())
            .ForMember(des => des.ProductName, opt => opt.Ignore())
            .ForMember(des => des.BasicUnitName, opt => opt.Ignore())
            .ForMember(des => des.OtherUnitName, opt => opt.Ignore());

        CreateMap<Warehouse, WarehouseDto>();
        CreateMap<Location, LocationDto>();
        CreateMap<DocumentNumberRule, DocumentNumberRuleDto>();

        CreateMap<ExpenseItem , ExpenseItemDto>();
    }
}
